<?php


namespace App\Http\Searchs\Order;


use Illuminate\Database\Query\Builder;
use LTools\Searchs\SearchAbstract;

class PickingShowSearch extends SearchAbstract
{

    /**
     * 关系映射.
     *
     * @return array
     */
    protected function relationship(): array
    {
        return [
            'code' => 'closure',
        ];
    }

    /**
     * @param $code
     * @return \Closure
     * @author luffyzhao@vip.126.com
     */
    protected function getCodeAttribute($code)
    {
        return function (Builder $builder) use ($code) {
            if (!empty($code)) {
                $builder->whereIn('order_id', function (Builder $builder) use ($code) {
                    $builder->from('orders')->select(['id']);
                    $builder->where('code', '=', $code);
                });
            };
        };
    }
}